﻿using System;
using System.Text;
using System.Collections;
using System.Xml;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Resources;
using System.Reflection;
using System.Globalization;
using System.Threading;

using Telerik.WebControls;
using UFSoft.UBF.UI.WebControls;
using UFSoft.UBF.UI.Controls;
using UFSoft.UBF.Util.Log;
using UFSoft.UBF.Util.Globalization;

using UFSoft.UBF.UI.IView;
using UFSoft.UBF.UI.Engine;
using UFSoft.UBF.UI.MD.Runtime;
using UFSoft.UBF.UI.ActionProcess;
using UFSoft.UBF.UI.WebControls.ClientCallBack;
using System.Collections.Generic;
using UFSoft.UBF.UI.FormProcess;
using UFSoft.UBF.UI.WebControlAdapter;
using UFSoft.UBF.UI.WebControls.Association;
using UFSoft.UBF.UI.WebControls.Association.Adapter;



/***********************************************************************************************
 * Form ID: 
 * UIFactory Auto Generator 
 ***********************************************************************************************/
namespace UFIDA.U9.Cust.U9Demo.DeliverUI
{
    public partial class FindPOShipLineUIFormWebPart
    {
        #region Custome eventBind
	
		 
				//OnQuery358_Click...
		private void OnQuery358_Click_Extend(object sender, EventArgs  e)
		{
            //调用模版提供的默认实现.--默认实现可能会调用相应的Action.
            this.Model.POShipLineDataView.Clear();
            //调用模版提供的默认实现.--默认实现可能会调用相应的Action.
            QueryPOShipLineViewRecord record = this.Model.QueryPOShipLineView.FocusedRecord;
            if (record != null)
            {
                UFIDA.U9.Cust.U9Demo.DeliveryBP.QueryDoc proxy = new DeliveryBP.QueryDoc();
                proxy.PO = record.PO;
                proxy.PO_DocNo = record.PODocNo;
                proxy.Supplier = record.Supplier;
                proxy.Supplier_Code = record.SupplierCode;
                proxy.Item = record.Item;
                proxy.Item_Code = record.ItemCode;
                // proxy.Date = record.Date ?? DateTime.MinValue;
                proxy.Item = record.Item;
                List<DeliveryBP.ResultDTO> resultList = proxy.Do();
                if (resultList != null)
                {
                    foreach (DeliveryBP.ResultDTO data in resultList)
                    {
                        POShipLineDataViewRecord dataRecord = this.Model.POShipLineDataView.AddNewUIRecord();
                        dataRecord.PO_DocNo = data.DocNo;
                        dataRecord.DocLineNo = data.DocLineNo;
                        dataRecord.DocSubLineNo = data.DocSubLine;
                        dataRecord.POShipLine = data.POShipLine;
                        dataRecord.Supplier = data.Supplier;
                        dataRecord.Supplier_Code = data.Supplier_Code;
                        dataRecord.Supplier_Name = data.Supplier_Name;
                        dataRecord.Qty = data.Qty;
                        dataRecord.Price = data.Price;
                        dataRecord.Item = data.Item;
                        dataRecord.Item_Code = data.Item_Code;
                        dataRecord.Item_Name = data.Item_Name;

                        //添加子实体时需要和主实体做关联关系
                        //dataRecord.SetParentRecord(this.Model.QuerySOView.FocusedRecord);
                    }
                }
            }

                OnQuery358_Click_DefaultImpl(sender,e);
		}	
		 
				//OnOK208_Click...
		private void OnOK208_Click_Extend(object sender, EventArgs  e)
		{
            //调用模版提供的默认实现.--默认实现可能会调用相应的Action.
            if (this.Model.POShipLineDataView.SelectRecords.Count > 0)
            {
                UFIDA.U9.Cust.U9Demo.DeliveryBP.Proxy.CreateDocProxy proxy = new DeliveryBP.Proxy.CreateDocProxy();
                if (this.NameValues["DucumentTypeID"] != null)
                {
                    proxy.DocumentType = Convert.ToInt64(this.NameValues["DucumentTypeID"].ToString());
                }
                if (this.NameValues["DocNo"] != null)
                {
                    proxy.DocNO = this.NameValues["DocNo"].ToString();
                }
                proxy.ResultDTO = new List<DeliveryBP.ResultDTOData>();
                foreach (POShipLineDataViewRecord record in this.Model.POShipLineDataView.SelectRecords)
                {
                    DeliveryBP.ResultDTOData data = new DeliveryBP.ResultDTOData();
                    data.Supplier = record.Supplier;
                    data.Supplier_Code = record.Supplier_Code;
                    data.Supplier_Code = record.Supplier_Name;
                    data.Item = record.Item;
                    data.Item_Code = record.Item_Code;
                    data.Item_Name = record.Item_Name;
                    data.DocNo = record.PO_DocNo;
                    data.DocLineNo = record.DocLineNo??0;
                    data.DocSubLine = record.DocSubLineNo ?? 0;
                    data.POShipLine = record.POShipLine ?? 0;
                    data.Qty = record.Qty;
                    data.Price = record.Price;
                    proxy.ResultDTO.Add(data);
                }
                long deliveryID = proxy.Do();
                if (deliveryID > 0)
                {
                    this.CurrentState["DeliveryID"] = deliveryID;
                    this.CloseDialog(true);
                }
            }
            else
            {
                throw new Exception("请选择数据");
            }

            OnOK208_Click_DefaultImpl(sender,e);
		}	
		 
				//OnCancel201_Click...
		private void OnCancel201_Click_Extend(object sender, EventArgs  e)
		{
			//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
			
		
			OnCancel201_Click_DefaultImpl(sender,e);
		}

		
            
            

		#region 自定义数据初始化加载和数据收集
		private void OnLoadData_Extend(object sender)
		{	
			OnLoadData_DefaultImpl(sender);
		}
		private void OnDataCollect_Extend(object sender)
		{	
			OnDataCollect_DefaultImpl(sender);
		}
		#endregion  

        #region 自己扩展 Extended Event handler 
		public void AfterOnLoad()
		{
            if (this.Model.QueryPOShipLineView.FocusedRecord == null)
                this.Model.QueryPOShipLineView.AddNewUIRecord();
		}

        public void AfterCreateChildControls()
        {
            //开启个性化     
            UFIDA.U9.UI.PDHelper.PersonalizationHelper.SetPersonalizationEnable((BaseWebForm)this, true);

            ((UFWebDataGridAdapter)this.DataGrid0).AllowSelectAllPage = true;

            Register_DataGrid_Customer_PoskBack();

            Register_DataGrid_Customer_PoskBackAll();

            Register_DataGrid_Customer_PoskBackAll2();
        }
        
        public void AfterEventBind()
        {
        }
        
		public void BeforeUIModelBinding()
		{

		}

		public void AfterUIModelBinding()
		{


		}


        private void Register_DataGrid_Customer_PoskBack()
        {

            AssociationControl gridCellDataChangedASC = new AssociationControl();       //基本固定代码
            gridCellDataChangedASC.SourceServerControl = this.DataGrid0;
            gridCellDataChangedASC.SourceControl.EventName = "OnBodyRowSelected";


            ClientCallBackFrm gridCellDataChangedCBF = new ClientCallBackFrm();
            gridCellDataChangedCBF.ParameterControls.Add(this.DataGrid0);

            gridCellDataChangedCBF.DoCustomerAction += new ClientCallBackFrm.ActionCustomer(gridCellDataChangedCBF_DoCustomerActionOfSubvillage);
            gridCellDataChangedCBF.Add(gridCellDataChangedASC);
            this.Controls.Add(gridCellDataChangedCBF);
        }

        private object gridCellDataChangedCBF_DoCustomerActionOfSubvillage(CustomerActionEventArgs args)
        {
            //this.OnDataCollect(this);
            //this.IsDataBinding = true; //当前事件执行后会进行数据绑定
            //this.IsConsuming = false;

            //this.DataGrid0.CollectData();
            //this.DataGrid0.BindData();

            ArrayList list = (ArrayList)args.ArgsHash[UFWebClientGridAdapter.ALL_GRIDDATA_SelectedRows]; //基本固定代码
            int count = list.Count;

            UFWebClientTextBoxAdapter seqAdapter = new UFWebClientTextBoxAdapter(this.TextBox213);
           string lbl = "已勾选数量：" + count;
            seqAdapter.Key = string.Empty;
            seqAdapter.Text = lbl;
            seqAdapter.Value = lbl;

            args.ArgsResult.Add(seqAdapter.ClientInstanceWithValue);

            return args;
        }

        void itemGriding_GridCustomerPostBackEvent(object sender, GridCustomerPostBackEventArgs e)
        {
            this.OnDataCollect(this);
            this.IsDataBinding = true; //当前事件执行后会进行数据绑定
            this.IsConsuming = false;

            this.DataGrid0.CollectData();
            this.DataGrid0.BindData();

            //if (this.DataGrid0.AllPageSelected)
            //    this.DataGrid0.AllPageSelected = false;
            //else
            //    this.DataGrid0.AllPageSelected = true;

           
            Label212.Text = "已勾选数量：" + this.Model.POShipLineDataView.GetSelectedRecordIDs().Length;
            this.CurrentSessionState["RoomCount"] = this.Model.POShipLineDataView.GetSelectedRecordIDs().Length;
        }

        private void Register_DataGrid_Customer_PoskBackAll()
        {
            AssociationControl gridCellDataChangedASC = new AssociationControl();       //基本固定代码
            gridCellDataChangedASC.SourceServerControl = this.DataGrid0;
            gridCellDataChangedASC.SourceControl.EventName = "OnSelecteAllPage";


            ClientCallBackFrm gridCellDataChangedCBF = new ClientCallBackFrm();
            gridCellDataChangedCBF.ParameterControls.Add(this.DataGrid0);

            gridCellDataChangedCBF.DoCustomerAction += new ClientCallBackFrm.ActionCustomer(gridCellDataChangedCBF_DoCustomerActionOfSubvillage);
            gridCellDataChangedCBF.Add(gridCellDataChangedASC);
            this.Controls.Add(gridCellDataChangedCBF);

        }

        void itemGriding_GridCustomerPostBackEventAll(object sender, GridCustomerPostBackEventArgs e)
        {
            this.OnDataCollect(this);
            this.IsDataBinding = true; //当前事件执行后会进行数据绑定
            this.IsConsuming = false;

            this.DataGrid0.CollectData();
            this.DataGrid0.BindData();



            Label212.Text = "已勾选数量：" + this.Model.POShipLineDataView.GetSelectRecords().Count;
            this.CurrentSessionState["RoomCount"] = this.Model.POShipLineDataView.GetSelectRecords().Count;
        }
        private void Register_DataGrid_Customer_PoskBackAll2()
        {

            AssociationControl gridCellDataChangedASC = new AssociationControl();       //基本固定代码
            gridCellDataChangedASC.SourceServerControl = this.DataGrid0;
            gridCellDataChangedASC.SourceControl.EventName = "OnSelectAllRecords";


            ClientCallBackFrm gridCellDataChangedCBF = new ClientCallBackFrm();
            gridCellDataChangedCBF.ParameterControls.Add(this.DataGrid0);

            gridCellDataChangedCBF.DoCustomerAction += new ClientCallBackFrm.ActionCustomer(gridCellDataChangedCBF_DoCustomerActionOfSubvillage);
            gridCellDataChangedCBF.Add(gridCellDataChangedASC);
            this.Controls.Add(gridCellDataChangedCBF);

        }

        void itemGriding_GridCustomerPostBackEventAll2(object sender, GridCustomerPostBackEventArgs e)
        {
            this.OnDataCollect(this);
            this.IsDataBinding = true; //当前事件执行后会进行数据绑定
            this.IsConsuming = false;

            this.DataGrid0.CollectData();
            this.DataGrid0.BindData();

            
            Label212.Text = "已勾选数量：" + this.Model.POShipLineDataView.GetSelectRecords().Count;
            this.CurrentSessionState["RoomCount"] = this.Model.POShipLineDataView.GetSelectRecords().Count;
        }



        #endregion

        #endregion

    }
}